package com.ruoyi.web.controller.hbs;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.hbs.domain.ProductArchive;
import com.ruoyi.hbs.service.ProductArchiveService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品档案主档Controller
 * 
 * @author ruoyi
 * @date 2025-11-14
 */
@RestController
@RequestMapping("/hbs/productArchive")
public class ProductArchiveController extends BaseController
{
    @Autowired
    private ProductArchiveService productArchiveService;

    /**
     * 查询产品档案主档列表
     */
    @PreAuthorize("@ss.hasPermi('hbs:productArchive:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductArchive productArchive)
    {
        startPage();
        List<ProductArchive> list = productArchiveService.selectProductArchiveList(productArchive);
        return getDataTable(list);
    }

    /**
     * 导出产品档案主档列表
     */
    @PreAuthorize("@ss.hasPermi('hbs:productArchive:export')")
    @Log(title = "产品档案主档", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductArchive productArchive)
    {
        List<ProductArchive> list = productArchiveService.selectProductArchiveList(productArchive);
        ExcelUtil<ProductArchive> util = new ExcelUtil<ProductArchive>(ProductArchive.class);
        util.exportExcel(response, list, "产品档案主档数据");
    }

    /**
     * 获取产品档案主档详细信息
     */
    @PreAuthorize("@ss.hasPermi('hbs:productArchive:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(productArchiveService.getById(id));
    }

    /**
     * 新增产品档案主档
     */
    @PreAuthorize("@ss.hasPermi('hbs:productArchive:add')")
    @Log(title = "产品档案主档", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductArchive productArchive)
    {
        return toAjax(productArchiveService.save(productArchive));
    }

    /**
     * 修改产品档案主档
     */
    @PreAuthorize("@ss.hasPermi('hbs:productArchive:edit')")
    @Log(title = "产品档案主档", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductArchive productArchive)
    {
        return toAjax(productArchiveService.updateById(productArchive));
    }

    /**
     * 删除产品档案主档
     */
    @PreAuthorize("@ss.hasPermi('hbs:productArchive:remove')")
    @Log(title = "产品档案主档", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(productArchiveService.removeBatchByIds(Arrays.asList(ids)));
    }
}
